package a1;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class RunProcessor {
    public void process(Class clazz) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Method[] declaredMethods = clazz.getDeclaredMethods();
        Object instance = null;
        for (Method declaredMethod : declaredMethods) {
            if (declaredMethod.isAnnotationPresent(Run.class)) {
                Run run = declaredMethod.getAnnotation(Run.class);
                if (instance == null) {
                    instance = clazz.getConstructor().newInstance();
                }
                if (instance != null) {
                    declaredMethod.invoke(instance);
                }
            }
        }

    }
}
